package com.review.demo.aop;



import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author xsyz
 * @created 2020-12-27   10:48
 */
//@Aspect
public class Aoptest {


    public static void main(String[] args) {
        Class[] interfaces = {Add.class};
        Addimpl addimpl = new Addimpl();
        Add o = (Add) Proxy.newProxyInstance(Aoptest.class.getClassLoader(), interfaces, new invoke(addimpl));
        o.add();
    }
}

class invoke implements InvocationHandler{
    private Object o;

    public invoke(Object o){
        this.o = o;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //方法之前
        System.out.println("方法之前。。。。。。。。。。"+method.getName());

        //增强方法
        Object res = method.invoke(o, args);


        //方法之后
        System.out.println("方法之后。。。。。。。。。。。"+method.getName());

        return res;
    }
}